package metadata;

import java.util.ArrayList;
import java.util.Hashtable;

import metadata.schema.*;
import storage.transaction.Transaction;

public class MetadataMgr {

	private static Hashtable<String, Database> databaseTable;
	private static ArrayList<Database> databases;
	private static int dbCount;
	
	public static void createIndex(String indexname, String tablename, String filedname, Transaction tx) {
		// TODO
	}

	public static void createTable(String tablename, Schema schema, Transaction tx) {
		// TODO �Զ���ɷ������
		
	}

	public static void createDB(String dbname, Transaction tx) {
		// TODO: transaction
		
		// check existence
		if (!databaseTable.containsKey(dbname)) {
			++dbCount;
			Database db = new Database(dbCount, dbname);
			databaseTable.put(dbname, db);
			databases.add(db);
			// TODO: write to disk
			
			// TODO: create files
		}
	}

	public static void dropDB(String dbname, Transaction tx) {
		// TODO �Զ���ɷ������
		
	}

	public static void dropIndex(String tablename, String indexname, Transaction tx) {
		// TODO �Զ���ɷ������
		
	}

	public static void dropTable(String tablename, Transaction tx) {
		// TODO �Զ���ɷ������
		
	}

	public static void useDB(String dbname, Transaction tx) {
		// TODO �Զ���ɷ������
		
	}

	public static Schema getTableInfo(String tablename, Transaction tx) {
		// TODO �Զ���ɷ������
		return null;
	}
	
	/*
	 * useful when creating tables
	 */
	public static Database getDatabase(String dbname) {
		return databaseTable.get(dbname);
	}

}
